<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateNoteEntityRelationTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('note_entity_relation', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '需求实体关联表']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('note_id', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '需求id',])
            ->addColumn('relation_type', 'string', ['null' => false, 'default' => '', 'limit' => 20, 'comment' => '关联类型(episode 集,entity 实体,step 工序)'])
            ->addColumn('relate_module_code', 'string', ['null' => false, 'default' => '', 'limit' => 20, 'comment' => '关联模块 (asset 资产 shot 镜头)'])
            ->addColumn('project_id', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '项目id',])
            ->addColumn('episode_code', 'string', ['null' => false, 'default' => '', 'limit' => 128, 'comment' => '集code'])
            ->addColumn('entity_id', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '实体id',])
            ->addColumn('task_id', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '任务id',])
            ->addColumn('version_id', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '版本id',])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建时间',])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建者'])
            ->save();
    }

    public function down()
    {
        $this->table('note_entity_relation')->drop()->save();
    }
}
